<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>    
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
    <title>WebService界面 </title>
	<link rel="stylesheet" href="${pageContext.request.contextPath}/css/bootstrap.min.css" />  
	<script src="${pageContext.request.contextPath}/js/jquery-1.11.3.min.js"></script>
	<script src="${pageContext.request.contextPath}/js/bootstrap.min.js"></script>
</head>
<body>
   <nav class="navbar navbar-default" role="navigation"> 
    <div class="container-fluid" style="width:808px;"> 
        <div class="navbar-header"> 
            <a class="navbar-brand" href="#">WebService管理平台</a> 
        </div> 
         <ul class="nav navbar-nav">
            <li>
                <a href="#" class="dropdown-toggle" data-toggle="dropdown">
                                                  日志管理 <b class="caret"></b>
                </a>
                <ul class="dropdown-menu">
                    <li><a href="#">添加日志</a></li>
                    <li><a href="#">日志查询</a></li>
                </ul>
            </li>
            <li>
                <a href="#" class="dropdown-toggle" data-toggle="dropdown">
                                                 任务管理 <b class="caret"></b>
                </a>
                 <ul class="dropdown-menu">
                    <li><a href="${pageContext.request.contextPath}/task/getNewTask.do">查询修改任务</a></li>
                    <li><a href="${pageContext.request.contextPath}/task/manager.do">任务管理</a></li>
                    <li><a href="${pageContext.request.contextPath}/jsp/corn.jsp">corn表达式</a></li>
                </ul>
            </li>
             <li class="active">
                <a href="#" class="dropdown-toggle" data-toggle="dropdown">
                                               配置文件管理 <b class="caret"></b>
                </a>
                <ul class="dropdown-menu">
                    <li><a href="${pageContext.request.contextPath}/properties/manager.do">配置文件管理</a></li>
                </ul>
            </li>
            <li class="dropdown">
                <a href="#" class="dropdown-toggle" data-toggle="dropdown">
                    Java <b class="caret"></b>
                </a>
                <ul class="dropdown-menu">
                    <li><a href="#">jmeter</a></li>
                    <li><a href="#">EJB</a></li>
                    <li><a href="#">Jasper Report</a></li>
                    <li class="divider"></li>
                    <li><a href="#">分离的链接</a></li>
                    <li class="divider"></li>
                    <li><a href="#">另一个分离的链接</a></li>
                </ul>
            </li>
        </ul>
         <ul class="nav navbar-nav navbar-right"> 
            <c:if test="${empty sessionScope.mainUser}">
            <li><a href="${pageContext.request.contextPath}/login/login.do">登录</a></li> 
            </c:if>
            <c:if test="${not empty sessionScope.mainUser}">
            <li><a href="${pageContext.request.contextPath}/login/out.do">退出</a></li> 
            </c:if>
        </ul> 
    </div> 
</nav>
 <div class="container-fluid" style="width:808px;">
	    <div class="form-group">
	    <select class="form-control" id="propertiesName">
	      <option value="">请选择选择</option>
	      <c:forEach items="${fileNames}" var="names">
	       <option value="${names}">${names}</option>
	      </c:forEach>
	    </select>
	    <p></p>
	    <textarea  class="form-control" id="propertiesCoutent" rows="10"></textarea>
	    <p></p>
	    <button type="button" id="saveContent" class="btn btn-default btn-lg btn-block">保存修改</button>
        </div>
    </div>
</body>
<script type="text/javascript">
    $("#propertiesName").change(function(){  
	    var name=$(this).val();
	    if(null==name||""==name){
	    	$("#propertiesCoutent").val("");
	    	return false;
	    }
	    $.ajax({
	    	   type: 'POST',
	    	   url: '${pageContext.request.contextPath}/properties/getContent.do',
	    	   dataType:'json',
	    	   contentType : 'application/json; charset=UTF-8',
	    	   data:JSON.stringify({'name':name}),
	    	   success: function(msg){
	    		 var json=eval(msg);
	    		 if("success"==json.result){
	    			 $("#propertiesCoutent").val(json.content);
	    		 }else{
	    			 alert("加载内容失败!");
	    		 }
	    	   },
	    	   error:function(msg){
	    		   alert("请求出错!");
	    	   }
	    	});
	})   
	
	$("#saveContent").click(function (){
		var name=$("#propertiesName").val();
		var content=$("#propertiesCoutent").val();
		$.ajax({
	    	   type: 'POST',
	    	   url: '${pageContext.request.contextPath}/properties/saveContent.do',
	    	   dataType:'json',
	    	   contentType : 'application/json; charset=UTF-8',
	    	   data:JSON.stringify({'name':name,'content':content}),
	    	   success: function(msg){
	    		 var json=eval(msg);
	    		 if("success"==json.result){
	    			 alert("保存成功!")
	    		 }else if("error"==json.result){
	    			 alert(json.message);
	    		 }else{
	    			 alert("保存失败!"+msg)
	    			 }
	    	   },
	    	   error:function(msg){
	    		   alert("请求出错!");
	    	   }
	    	});
	})
</script>
</html>